<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
	version="1.0" 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
	xmlns:msxml="urn:schemas-microsoft-com:xslt"
	xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.examine="urn:umbraco.examine" xmlns:Utils="urn:Utils" 
	exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.examine Utils ">


  <xsl:output method="xml" omit-xml-declaration="yes"/>

  <xsl:param name="currentPage"/>
  <xsl:param name="rootNode" select="$currentPage/ancestor-or-self::Intro" />
  <xsl:variable name="totalMenu" select="count($rootNode/child::*[self::WebPage or self::List or self::ContactPage ][commonHideOnNavigation !=1])"/>

  <xsl:template match="/">

    <!-- start writing XSLT -->
    <!--contar filhos a partir do rootnode, homepage-->
    <xsl:if test="$totalMenu>0">
      <nav>
        <ul class="sf-menu">
          <li>
            <xsl:attribute name="class">
              palogo
            </xsl:attribute>
            <!--</li>
            <li> 
            <xsl:attribute name="class">
              home
            </xsl:attribute>-->
            <a href="{umbraco.library:NiceUrl($rootNode/@id)}">
              <xsl:choose>
                <xsl:when test="$rootNode/commonName!=''">
                  <xsl:value-of select="$rootNode/commonName" />
                </xsl:when>
                <xsl:otherwise>
                  <xsl:value-of select="$rootNode/@nodeName" />
                </xsl:otherwise>
              </xsl:choose>
            </a>
          </li>
          <xsl:for-each select="$rootNode/child::*[self::WebPage or self::List or self::ContactPage][commonHideOnNavigation !=1]">
            <xsl:call-template name="drawMenuItem">
              <xsl:with-param name="currentNode" select="."></xsl:with-param>
              <xsl:with-param name="writeLiLast" select="position()"></xsl:with-param>
            </xsl:call-template>
          </xsl:for-each>
        </ul>
        <div class="clear">

        </div>
      </nav>
    </xsl:if>
  </xsl:template>

  <xsl:template name="drawMenuItem">
    <xsl:param name="currentNode"/>
    <xsl:param name="writeLiLast"/>
    <li>
      <xsl:choose>
        <xsl:when test="$currentNode/@id = $currentPage/@id">
          <xsl:choose>
            <xsl:when test="$writeLiLast=$totalMenu">
              <xsl:attribute name="class">active last</xsl:attribute>
            </xsl:when>
            <xsl:otherwise>
              <xsl:attribute name="class">active</xsl:attribute>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
      </xsl:choose>
      <a href="{umbraco.library:NiceUrl($currentNode/@id)}">
        <xsl:choose>
          <xsl:when test="$currentNode/commonName!=''">
            <xsl:value-of select="$currentNode/commonName" />
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="$currentNode/@nodeName" />
          </xsl:otherwise>
        </xsl:choose>
      </a>
      <xsl:if test="count($currentNode/child::*[self::WebPage or self::List or self::ContactPage][commonHideOnNavigation !=1]) > 0 and $currentNode/@level &lt; 5">
        <ul>
          <xsl:for-each select="$currentNode/child::*[self::WebPage or self::List or self::ContactPage][commonHideOnNavigation !=1 and @level &lt;6]">
            <xsl:call-template name="drawMenuItem">
              <xsl:with-param name="currentNode" select="."></xsl:with-param>
              <xsl:with-param name="writeLiLast" select="0"></xsl:with-param>
            </xsl:call-template>
          </xsl:for-each>
        </ul>
      </xsl:if>
    </li>
  </xsl:template>

</xsl:stylesheet>